package com.vayne.demo;

import com.vayne.api.DefaultPersonFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * 如果三种初始化都使用了，那么输出优先级是：
 * 1）PostConstruct init
 * 2）afterPropertiesSet init
 * 3）InitMethod init
 *
 * @author xuerui.zhang
 * @since 2020/4/7 上午10:07
 */
public class BeanInitializationDemo {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(BeanInitializationDemo.class);

        // 启动应用上下文
        applicationContext.refresh();

        applicationContext.getBean(DefaultPersonFactory.class);

        // 关闭应用上下文
        applicationContext.close();
    }

    @Bean(initMethod = "initPersonFactory")
    public DefaultPersonFactory personFactory() {
        return new DefaultPersonFactory();
    }
}
